{
Traviesadora beta 0.2.0.13.33 (30.11.2008)
LastMod: 18.12.2008 by Prof1983

Copyright 2008, travieorama@googlemail.com

This file is part of the taviesadora project

taviesadora is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

taviesadora is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
}
unit DialogWin;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TFrmDialog = class(TForm)
    Bevel1: TBevel;
    lblDiagText: TLabel;
    Image1: TImage;
    imgClose: TImage;
    lblCaption: TLabel;
    procedure xpButtonClick(Sender: TObject);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure Image1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure imgCloseMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure imgCloseMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure imgCloseClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    XOrig: Integer;
    YOrig: Integer;
    ModalMode: Boolean;
    owner: TObject;
    procedure IniWin(Title: string; Text: string; ButtonList: TStringList);
  public
    constructor CreateNotModal(Owner: TObject; Title: string; Text: string; ButtonList: TStringList);
    function ShowModalA(Title: string; Text: string; ButtonList: TStringList): Integer;
  end;

var
  FrmDialog: TFrmDialog;

implementation

uses
  NobraClientThread;

{$R *.dfm}

{ TFrmDialog }

procedure TFrmDialog.IniWin(Title: string; Text: string; ButtonList: TStringList);
var
  i: Integer;
  XPButton: TButton;
begin
  lblDiagText.Caption := Text;
  caption := Title;
  lblCaption.Caption := Title;
  lblDiagText.Left := 70;
  lblDiagText.Width := Width - lblDiagText.Left * 2;
  imgClose.Left := Width - imgClose.Width - 2;
  Image1.Left := 1;
  Image1.Width := imgClose.Left - Image1.Left;
  if ButtonList.count = 0 then
  begin
    ButtonList.Add('OK');
  end;
  for i := 0 to ButtonList.Count - 1 do
  begin
    XPButton := TButton.Create(Self);
    XPButton.Tag := i + 1;
    XPButton.Caption := ButtonList[i];
    XPButton.Font.Color := $00252558;
    XPButton.Top := Height -35;
    XPButton.Width := Canvas.TextWidth(XPButton.Caption) + 20;
    if (XPButton.Width < 60) then
      XPButton.Width := 60;
    XPButton.Left := (Width div (ButtonList.Count+1)) * (i+1) - XPButton.Width div 2;
    XPButton.Parent := Self;
    XPButton.OnClick := xpButtonClick;
  end;
end;

constructor TFrmDialog.CreateNotModal(owner: TObject; Title, Text: string; ButtonList: TStringList);
begin
  inherited Create(Application);
  Self.Owner := Owner;
  IniWin(Title, Text, ButtonList);
  ModalMode := False;
  Show;
end;

function TFrmDialog.ShowModalA(Title: string; Text: string; ButtonList: TStringList): Integer;
begin
  IniWin(Title, Text, ButtonList);
  ModalMode := True;
  Result := ShowModal();
end;

procedure TFrmDialog.xpButtonClick(Sender: TObject);
var
  XPbutton: TButton;
  res: TNobraChatAcceptAnswer;
begin
  XPbutton := nil;
  if Sender is TButton then
    XPbutton := Sender as TButton;
  if Assigned(XPbutton) then
  begin
    if ModalMode then
      ModalResult := XPbutton.Tag
    else begin
      case XPbutton.Tag of
        1: res := ncaYes;
        2: res := ncaAlwaysYes;
        3: res := ncaNo;
        4: res := ncaBlock;
      end;
      if Assigned(owner) then
        if owner is TConData then
          (owner as TConData).SetChatAcceptAnswer(res);
      Close;
    end;
  end;
end;

procedure TFrmDialog.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  XOrig := X;
  YOrig := Y;
  image1.Tag := 1;
end;

procedure TFrmDialog.Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  if (Image1.Tag = 1) then
  begin
    Left := Left-(XOrig-x);
    Top := Top-(YOrig-y);
  end;
end;

procedure TFrmDialog.Image1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  image1.Tag := 0;
end;

procedure TFrmDialog.imgCloseMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  imgClose.Top := imgClose.Top + 1;
  imgClose.left := imgClose.Left + 1;
  imgClose.Tag := 1;
end;

procedure TFrmDialog.imgCloseMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if (imgClose.Tag = 1) then
  begin
    imgClose.Top := imgClose.Top - 1;
    imgClose.Left := imgClose.Left - 1;
    imgClose.Tag := 0;
  end;
end;

procedure TFrmDialog.imgCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TFrmDialog.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if not ModalMode then
  begin
    if Assigned(Owner) then
     if Owner is TConData then
        (Owner as TConData).SetfrmChatAcceptAnswer(nil);
    Action := caFree;
  end;
end;

end.
